package yxy.game.pm2.chat.module;

import yxy.game.pm2.bean.PlayerBean;
import yxy.game.pm2.bean.area.AreaBean;
import yxy.game.pm2.bean.area.ChatChannelType;
import yxy.game.pm2.bean.module.AreaModule;

public class ChatChannel_Area extends BaseChatChannelModule {

	private int areaId;

	public ChatChannel_Area(int areaId) {
		this.areaId = areaId;
	}

	public int getAreaId() {
		return areaId;
	}

	@Override
	protected int historySize() {
		return 20;
	}

	@Override
	protected ChatChannelType getChannelType() {
		return ChatChannelType.CHAT_AREA;
	}

	@Override
	protected String key() {
		return String.format("CHAT:AREA:%s:MSG", getAreaId());
	}

	@Override
	protected String keySub() {
		return String.format("CHAT:AREA:%s:SUB", getAreaId());
	}

	public static ChatChannel_Area get(PlayerBean playerBean) {
		if (playerBean == null) {
			return null;
		}
		AreaBean areaBean = AreaModule.area(playerBean);
		if (areaBean == null) {
			return null;
		}
		return new ChatChannel_Area(areaBean.getAreaId());
	}

	public static ChatChannel_Area get(int areaId) {
		AreaBean areaBean = AreaBean.get(areaId);
		if (areaBean == null || areaBean.isMeraged()) {
			return null;
		}
		return new ChatChannel_Area(areaId);
	}

}
